#prime.py 用于生成两个素数p,q
from sympy import nextprime
import random
class Prime:
    def __init__(self,bits):
        self.bits=bits
    # 生成一个512位的随机数
    def generate_large_prime(self,bits):
        random_number = random.getrandbits(bits)
        return nextprime(random_number)
    # 保存p和q到文件
    def save_to_file(self,filename, **kwargs):
        with open(filename, 'w') as file:
            for key, value in kwargs.items():
                file.write(f"{key}={value}\n")
            print(f"内容已保存到 {filename}")
'''if __name__ == '__main__':
    # 生成两个512位的素数
    p = generate_large_prime()
    q = generate_large_prime()
    print(f"生成的素数 p: {p}")
    print(f"生成的素数 q: {q}")
    # 保存到文件
    save_to_file("rsa.txt", p=p, q=q)'''
